﻿using System;
using System.Windows.Forms;
using Saturn.App.FormOper;
using System.Data;
using Saturn.App.Common;

namespace Saturn.App
{
    public partial class FormCheck : Form
    {
        SaturnWebReference.SaturnWebService soap = new Saturn.App.SaturnWebReference.SaturnWebService();
        public FormCheck()
        {
            InitializeComponent();
            GetNowBillCode(); //自动加载正在执行的订单号
        }

        private void FrmSendList_Load(object sender, EventArgs e)
        {
            this.txt_billcode.Focus();
            //DataBind();
        }



        private void btnNext_Click(object sender, EventArgs e)
        {
            //if (pageIndex == pageCount || pageCount == 0)
            //{
            //    CommonSound.MessageBeep(CommonSound.Information);
            //    MessageBox.Show("当前是最后一页！", "Error");
            //    return;
            //}
            //else
            //{
            //    pageIndex++;
            //    DataBind();
            //}
        }
        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txt_billcode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)13)
            {
                this.txt_productbar.Enabled = true;
            }
        }

        private void txt_productbar_KeyDown(object sender, KeyEventArgs e)
        {
            //string billcode = txt_billcode.Text.ToString();
            //if (String.IsNullOrEmpty(billcode))
            //{
            //    CommonSound.MessageBeep(CommonSound.Information);
            //    MessageBox.Show("生产订单号未扫描！", "Error");
            //    return;
            //}
            //string productbar = txt_productbar.Text.ToString();
            //if (String.IsNullOrEmpty(productbar))
            //{
            //    CommonSound.MessageBeep(CommonSound.Information);
            //    MessageBox.Show("商品条码未扫描！", "Error");
            //    return;
            //}
        }

        private void btn_finish_Click(object sender, EventArgs e)
        {
            string billcode = txt_billcode.Text.ToString();
            if (String.IsNullOrEmpty(billcode))
            {
                CommonSound.MessageBeep(CommonSound.Information);
                MessageBox.Show("生产订单号未扫描！", "Error");
                return;
            }
            string productbar = txt_productbar.Text.ToString();
            if (String.IsNullOrEmpty(productbar))
            {
                CommonSound.MessageBeep(CommonSound.Information);
                MessageBox.Show("商品条码未扫描！", "Error");
                return;
            }
            string res = soap.AddBillPerformvalida(int.Parse(CommonCfg.Locationid), billcode, productbar, DateTime.Now, DateTime.Now, CommonCfg.Userrealname);
            MessageBox.Show(res);
        }


        private void GetNowBillCode()
        {
            try
            {
                DataSet ds = soap.GetNowBillCode();
                DataTable dt = ds.Tables[0];

                if (dt.Rows.Count <= 0)
                {
                    MessageBox.Show("今天没有执行的计划单据！");
                    return;
                }
                else
                    this.txt_billcode.Text = dt.Rows[0]["billcode"].ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现网络故障，请检查设备与服务器连接是否正常");
                return;
            }

        }


    }
}